Version Control
It is all about keeping track of changes 📓✍️
03:00 Follow instructions in Version Control - git hell (a separate presentation).
Getting all the necessary software installed, configured, and playing nicely together is honestly half the battle … Brace yourself for some pain
You will still need to know the basics of shell.
GUI = Graphical User Interface
I will be showing you how to use:
The {usethis} package is a collection of functions that help various tasks in R.
Install the package by running:
call a function by running:
Activate git for a repo
Git integration is automatic in Source control panel
Create new project with git tracking
05:00 A commit is a record of a change
If you create or edit a file in your repository and save the changes, you need to record your change via a commit
Chess move diary:
Pawn to d4
Edit line 32 of file A
Make a change to a file and save it. Now stage the change:
05:00 Commit (record) staged changes:
$ git log --stat
commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 16:40:33 2008 -0700
Remove unnecessary test
lib/simplegit.rb | 5 -----
1 file changed, 5 deletions(-)
commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <schacon@gee-mail.com>
Date: Sat Mar 15 10:31:28 2008 -0700
Initial commit
README | 6 ++++++
Rakefile | 23 +++++++++++++++++++++++
lib/simplegit.rb | 25 +++++++++++++++++++++++++
3 files changed, 54 insertions(+)SHA - unique identifier
Author - who has done this?
Date - when was this done?
Message - description of what has been done
Stats - what has changed?
05:00 Commits are quick and cheap. Therefore:
Now we need to sync chnages with the remote using PUSH
Add a remote to existing local repo (only once):
Push local to remote (GitHub):
Add a remote to existing local repo (only once):
Push local to remote (GitHub):
Add a remote to existing local repo (only once):
Push local to remote (GitHub):
05:00 Now we need to sync chnages from the remote to local the using PULL
README - description of the project
.gitignore - list of files ignored by GitHub (more about it later)
license - tell other what they can do wit your code
05:00 Copy (download) from remote repo to local machine
Example of online repo: SSoQE/VersionControl-playground
Clone repo using new project in RStudio GUI or via {usethis} package:
Open Command Palette (Ctrl+Shift+p)
Paste in URL: "https://github.com/<OWNER>/<REPO>.git"
clone a repo (e.g. any repo from SSoQE)
05:00 A merge conflict can occur when you are changing the same line in one file differently.
To https://github.com/picardis/myrepo.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/picardis/myrepo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.a good strategy to avoid such conflicts:
Merge conflicts cannot always be avoided (but can be mitigated by branches - NOT PART OF THIS LECTURE).
How to undo last commit?
Variant A: I commited but NOT pushed yet.
RStudio has a range of possibilities to work with Git and GitHub as shown in this tutorial. The Terminal (NOT console) has more commands and options and will be handy for trouble shooting.
Open Command Palette (Ctrl+Shift+p)
Write Git: Undo Last Commit
How to undo last commit?
Variant B: I commited but AND pushed already.
We need the Terminal (NOT console) again.
Copy the SHA of the last commit
Need to push the changes to the remote repo:
In the Source control panel -> COMMITS section -> Right-click on the commit you want to revert to -> Select the Reset Current Branch to Previous Commit
Right-click on the commit you would like to undo to and select Revert a commit.
The materials used in this presentation are further expanded in a greater detail in course Science Powered through Reproducibility, Openness, and Teamwork (SPRouT) taught at Charles University.
Ondřej Mottl Assistant Professor at Charles University
Head of the 🧑💻 Laboratory of Quantitative Ecology